using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Diagnostics;
using System.Data;
using System.DirectoryServices;
using System.IO;
using System.Security.Principal;
using System.Web.Configuration;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using Microsoft.LearningComponents;
using Microsoft.LearningComponents.Storage;
using Schema = BasicWebPlayer.Schema;
using LearningComponentsHelper;
public class BasicWebPlayerBase : PageHelper
{
protected void RequestMyTraining(LearningStoreJob job,
PackageItemIdentifier packageId)
{
LearningStoreQuery query = LStore.CreateQuery(Schema.MyAttemptsAndPackages.ViewName);
query.AddColumn(Schema.MyAttemptsAndPackages.PackageId);
query.AddColumn(Schema.MyAttemptsAndPackages.PackageFileName);
query.AddColumn(Schema.MyAttemptsAndPackages.OrganizationId);
query.AddColumn(Schema.MyAttemptsAndPackages.OrganizationTitle);
query.AddColumn(Schema.MyAttemptsAndPackages.AttemptId);
query.AddColumn(Schema.MyAttemptsAndPackages.UploadDateTime);
query.AddColumn(Schema.MyAttemptsAndPackages.AttemptStatus);
query.AddColumn(Schema.MyAttemptsAndPackages.TotalPoints);
query.AddSort(Schema.MyAttemptsAndPackages.UploadDateTime,
LearningStoreSortDirection.Ascending);
query.AddSort(Schema.MyAttemptsAndPackages.OrganizationId,
LearningStoreSortDirection.Ascending);
if (packageId != null)
{
query.AddCondition(Schema.MyAttemptsAndPackages.PackageId,
LearningStoreConditionOperator.Equal, packageId);
}
job.PerformQuery(query);
}
protected void GetMyTrainingResultsToHtml(DataTable dataTable,
Table htmlTable)
{
PackageItemIdentifier previousPackageId = null;
foreach (DataRow dataRow in dataTable.Rows)
{
PackageItemIdentifier packageId;
LStoreHelper.CastNonNull(dataRow[Schema.MyAttemptsAndPackages.PackageId],
out packageId);
string packageFileName;
LStoreHelper.CastNonNull(dataRow[Schema.MyAttemptsAndPackages.PackageFileName],
out packageFileName);
ActivityPackageItemIdentifier organizationId;
LStoreHelper.CastNonNull(dataRow[Schema.MyAttemptsAndPackages.OrganizationId],
out organizationId);
string organizationTitle;
LStoreHelper.CastNonNull(dataRow[Schema.MyAttemptsAndPackages.OrganizationTitle],
out organizationTitle);
AttemptItemIdentifier attemptId;
LStoreHelper.Cast(dataRow[Schema.MyAttemptsAndPackages.AttemptId],
out attemptId);
DateTime? uploadDateTime;
LStoreHelper.Cast(dataRow[Schema.MyAttemptsAndPackages.UploadDateTime],
out uploadDateTime);
AttemptStatus? attemptStatus;
LStoreHelper.Cast(dataRow[Schema.MyAttemptsAndPackages.AttemptStatus],
out attemptStatus);
float? score;
LStoreHelper.Cast(dataRow[Schema.MyAttemptsAndPackages.TotalPoints],
out score);
bool samePackage = ((previousPackageId != null) &&
(packageId.GetKey() == previousPackageId.GetKey()));
TableRow htmlRow = new TableRow();
htmlRow.ID = "Package" + packageId.GetKey().ToString();
string trainingName;
if (organizationTitle.Length == 0)
trainingName = packageFileName;
else
trainingName = String.Format("{0} - {1}", packageFileName, organizationTitle);
TableCell htmlCell = new TableCell();
if (samePackage)
htmlCell.CssClass = "Select_ SamePackage_";
else
{
htmlCell.CssClass = "Select_ NewPackage_";
CheckBox checkBox = new CheckBox();
checkBox.ID = "Select" + packageId.GetKey().ToString();
checkBox.Attributes.Add("onclick", "OnSelectionChanged()");
checkBox.ToolTip = "Select";
htmlCell.Controls.Add(checkBox);
}
htmlRow.Cells.Add(htmlCell);
htmlCell = new TableCell();
htmlCell.CssClass = "Name_";
HtmlAnchor anchor = new HtmlAnchor();
if (attemptId == null)
{
anchor.HRef = String.Format("javascript:OpenTraining('Org:{0}')",
organizationId.GetKey());
anchor.ID = String.Format("Org_{0}", organizationId.GetKey());
anchor.Attributes.Add("title", "Begin training");
}
else
{
anchor.HRef = String.Format("javascript:OpenTraining('Att:{0}')",
attemptId.GetKey());
anchor.Attributes.Add("title", "Continue training");
}
anchor.InnerText = trainingName;
htmlCell.Controls.Add(anchor);
htmlRow.Cells.Add(htmlCell);
htmlCell = new TableCell();
htmlCell.CssClass = "Uploaded_";
htmlCell.Wrap = false;
htmlCell.Text = NoBr(Server.HtmlEncode(
String.Format("{0:d} {0:t}", uploadDateTime)));
htmlRow.Cells.Add(htmlCell);
string attemptStatusString;
if (attemptStatus == null)
attemptStatusString = "Not Started";
else
attemptStatusString = attemptStatus.ToString();
htmlCell = new TableCell();
htmlCell.CssClass = "Status_";
htmlCell.Wrap = false;
if (attemptId != null)
{
anchor = new HtmlAnchor();
anchor.HRef = String.Format("javascript:ShowLog({0})", attemptId.GetKey());
anchor.InnerHtml = NoBr(Server.HtmlEncode(attemptStatusString));
anchor.Attributes.Add("title", "Show Log");
htmlCell.Controls.Add(anchor);
}
else
htmlCell.Text = NoBr(Server.HtmlEncode(attemptStatusString));
htmlRow.Cells.Add(htmlCell);
string scoreString;
if (score == null)
scoreString = "";
else
scoreString = String.Format("{0:0}%", Math.Round(score.Value));
htmlCell = new TableCell();
htmlCell.CssClass = "Score_";
htmlCell.Wrap = false;
htmlCell.Text = NoBr(Server.HtmlEncode(scoreString));
htmlRow.Cells.Add(htmlCell);
htmlTable.Rows.Add(htmlRow);
previousPackageId = packageId;
}
}
protected static string NoBr(string html)
{
return "<nobr>" + html + "</nobr>";
}
}